﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TestOnlineProject.Models.Entities;

namespace TestOnlineProject.Models.DataAccess
{
    public class SectionQuestionDAO
    {
        TestOnlineDBEntities db = new TestOnlineDBEntities();

        public SectionQuestion SelectBySectionIdQuestionId(int sectionId, int questionId)
        {
            var sectionQuestion = db.SectionQuestions.Where(s => (s.SectionId == sectionId && s.QuestionId == questionId)).FirstOrDefault();
            return sectionQuestion;
        }

        public List<SectionQuestion> SelectBySectionId(int sectionId)
        {
            var sectionQuestions = db.SectionQuestions.Where(s => (s.SectionId == sectionId)).ToList();
            return sectionQuestions;
        }

        public int Insert(SectionQuestion sectionQuestion)
        {
            db.SectionQuestions.AddObject(sectionQuestion);
            int result = db.SaveChanges();
            return result;
        }

        public int Delete(int sectionId, int questionId)
        {
            var sectionQuestion = db.SectionQuestions.Where(s => (s.SectionId == sectionId && s.QuestionId == questionId)).FirstOrDefault();
            db.SectionQuestions.DeleteObject(sectionQuestion);
            var result = db.SaveChanges();
            return result;
        }
    }
}